import { useHistory, useRouteMatch } from "react-router";
import { useEffect } from "react";
import { ipcRenderer, remote } from "electron";
import { Language } from "@anyshare/common/lib/constants";

export default function () {
    const history = useHistory();
    const { params } = useRouteMatch<{ 0: Language }>();

    useEffect(() => {
        ipcRenderer.send("blankwindowready", remote.getCurrentWindow().id);
    }, []);

    useEffect(() => {
        const onRedirect = (_event: any, url: string) => {
            history.replace(`/${params[0]}/${url}`);
        };
        ipcRenderer.once("redirect", onRedirect);
        return () => {
            ipcRenderer.removeListener("redirect", onRedirect);
        };
    }, [params, history]);

    return null;
}
